/*
	protocolo basico de redis
	*<numero de argumentos> CR LF
	$<numero de bytes del argumento 1> CR LF
	<argumento 1> CR LF
	...
	$<numero de bytes del argumento N> CR LF
	<argumento N> CR LF
*/

function RedisGet (clave) {
	client.write ('*2');
	client.write ('\r\n');
	
	client.write ('$3');
	client.write ('\r\n');
	client.write ('GET')
	client.write ('\r\n');
	
	client.write ('$' + clave.length);
	client.write ('\r\n');
	client.write (clave);
	client.write ('\r\n');
}

function RedisSet (clave, data) {
	client.write ('*3');
	client.write ('\r\n');
	
	client.write ('$3');
	client.write ('\r\n');
	client.write ('SET')
	client.write ('\r\n');
	
	client.write ('$' + clave.length);
	client.write ('\r\n');
	client.write (clave);
	client.write ('\r\n');
	
	client.write ('$' + data.length);
	client.write ('\r\n');
	client.write (data, 'binary');
	client.write ('\r\n');
}

function RedisPing () {
	client.write ('PING');
	client.write ('\r\n');
}

// graba valor en redis

var REDIS_PORT = 6379;

var net = require ('net');

var client = new net.Socket ();

client.on ('data', function (data) {
	console.log (data.toString('utf8'));
}); 

client.connect (REDIS_PORT, '127.0.0.1');

RedisPing ();

var datos = new Buffer ([50,51,52,53,54,55,56,57,58,59]);
RedisSet ("select * from pepino", datos);

var i = 0;
for (i = 0; i<100; ++ i)
RedisGet ("select * from pepino");

setTimeout (function (){ client.end(); }, 100);

